#include "IRCMainWindow.h"
#include "ui_IRCMainWindow.h"
#include "connectdialog.h"
#include "qircservice.h"
#include "msgstreamwidget.h"
#include <qdebug.h>

IRCMainWindow::IRCMainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::IRCMainWindow)
{
    ui->setupUi(this);

    m_irc = new QIrcService();
    QObject::connect(m_irc,SIGNAL(response(QString)),this, SLOT(serverResponse(QString)));
    QObject::connect(m_irc,SIGNAL(onPrivMsg(QString,QString,QString)),this, SLOT(onPrivateMessage(QString,QString,QString)));
    QObject::connect(m_irc,SIGNAL(onJoinEvent(QString,QString)),this, SLOT(onJoinEvent(QString,QString)));

    //TODO: Test Code
    MsgStreamWidget* widget = new MsgStreamWidget(this);
    ui->stackedWidget->insertWidget(0,widget);
    ui->stackedWidget->setCurrentIndex(0);

}

IRCMainWindow::~IRCMainWindow()
{
    delete ui;
}

void IRCMainWindow::changeEvent(QEvent *e)
{
    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void IRCMainWindow::connectToServerAction()
{
    ConnectDialog dialog;

    dialog.setSizeGripEnabled(false);

    if(dialog.exec() == QDialog::Accepted) {
        m_irc->connectToServer(dialog.getServerName(), dialog.getNickName(), dialog.getAltNickName(),dialog.getFullName(),6667);
    }
}

void IRCMainWindow::disconnectAction()
{

}

void IRCMainWindow::serverResponse(QString str)
{
    qDebug() << str;
}

void IRCMainWindow::onPrivateMessage(QString from, QString to, QString msg)
{

}

void IRCMainWindow::onJoinEvent(QString user, QString channel)
{

}

